package io.renren.common.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
import org.springframework.ui.Model;

import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.shiro.ShiroUtils;

@Aspect
@Component
public class UserAspect {
    
    
    @Pointcut("execution (public * io.renren.modules.front.controller..*.*(..))")
    public void userPointCut() { 
        
    }
    
    @Around("userPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        
        Object[] args = point.getArgs();
        
        for(Object arg : args) {
            if( arg instanceof Model) {
                Model model = (Model)arg;
                SysUserEntity user = ShiroUtils.getUserEntity();
                if(user != null) model.addAttribute("user", user);
            }
        }
        
        //执行方法
        Object result = point.proceed();
        
        

        return result;
    }
}
